
package UI;

import BLL.LoginService;
import DAL.ManagerDao;
import DAL.OperatorDao;
import Entity.Manager;
import Entity.Operator;
import Utils.TSUtility;

import java.util.Scanner;


/**
 * @Author Chen
 * @Date 2022/1/6 17:05
 * @Version 1.0
 * 登录人员选择界面
 */

public class SignIn {
    public static void main(String[] args) throws Exception {
        sign();
    }

    public static void sign() throws Exception {
        ManagerDao managerDao = new ManagerDao();
        OperatorDao operatorDao = new OperatorDao();
        Manager manager = new Manager();
        Operator operator = new Operator();
        Scanner sc = new Scanner(System.in);
        boolean option = true;
        while (option) {
            System.out.println("************图书管理系统***********");
            System.out.println("1.管理员登录");
            System.out.println("2.操作员登录");
            System.out.println("3.注册或忘记密码");
            System.out.println("4.修改密码");
            System.out.println("5.退出");
            System.out.println("请选择：");
            String number = sc.next();
            switch (number) {
                case "1":
                    System.out.println("请输入管理员id:");
                    String id = TSUtility.readKeyBoard(6, false);
                    System.out.println("请输入密码：");
                    String password = TSUtility.readKeyBoard(11, false);
                    if (managerDao.selectBYManager(id) == null) {
                        System.out.println("该管理员不存在");
                        break;
                    }
                    LoginService.Login(managerDao.selectBYManager(id), password);

                    ManagerUI.ui();
                    break;
                case "2":
                    System.out.println("请输入操作员id:");
                    String id1 = TSUtility.readKeyBoard(6, false);
                    System.out.println("请输入密码：");
                    String password1 = TSUtility.readKeyBoard(11, false);
                    if (operatorDao.selectBYOperator(id1) == null) {
                        System.out.println("该管理员不存在");
                        break;
                    }
                    LoginService.operatorLogin(operatorDao.selectBYOperator(id1), password1);
                    OperatorUI.ui();
                    break;
                case "3":
                    boolean option1 = true;
                    while (option1) {
                        System.out.println("************图书管理系统***********");
                        System.out.println("1.管理员注册");
                        System.out.println("2.忘记密码");
                        System.out.println("3.退出");
                        System.out.println("请选择：");

                        String number1 = sc.next();
                        switch (number1) {
                            case "1":
                                System.out.println("请输入你要注册的id号：");
                                String id2 = TSUtility.readKeyBoard(11, false);
                                System.out.println("请输入你的密码:");
                                String password2 = TSUtility.readKeyBoard(11, false);
                                if (managerDao.selectBYManager(id2) != null) {
                                    System.out.println("该账号已存在！！！");
                                    break;
                                }
                                LoginService.addManager(id2, password2);
                                break;
                            case "2":
                                boolean option3 = true;
                                while (option3) {
                                    System.out.println("************图书管理系统***********");
                                    System.out.println("1.管理员找回密码");
                                    System.out.println("2.操作员找回密码");
                                    System.out.println("3.退出");
                                    System.out.println("请选择：");
                                    String number3 = sc.next();
                                    switch (number3) {
                                        case "1":
                                            System.out.println("请输入管理员编号：");
                                            String Number = TSUtility.readKeyBoard(11, false);
                                            System.out.println("请输入设置新密码：");
                                            String newPassWord = TSUtility.readKeyBoard(11, false);
                                            if (managerDao.selectAdminByName(Number) == null) {
                                                System.out.println("没有该管理员！！！");
                                                break;
                                            }
                                            LoginService.ManagerPassWord(Number, newPassWord);

                                            break;
                                        case "2":
                                            System.out.println("请输入操作员编号：");
                                            String Number1 = TSUtility.readKeyBoard(11, false);
                                            System.out.println("请输入设置新密码：");
                                            String newPassWord1 = TSUtility.readKeyBoard(11, false);
                                            if (operatorDao.selectBYOperator(Number1) == null) {
                                                System.out.println("没有该操作员！！！");
                                                break;
                                            }
                                            LoginService.OperatorPassWord(Number1, newPassWord1);

                                            break;
                                        case "3":
                                            option3 = false;
                                            break;
                                        default:
                                            System.out.println("没有" + number3 + "这个选项！");
                                            break;
                                    }
                                }
                                break;
                            case "3":
                                option1 = false;
                                break;
                            default:
                                System.out.println("没有" + number1 + "这个选项！");
                                break;
                        }
                    }
                    break;
                case "4":
                    boolean option2 = true;
                    while (option2) {
                        System.out.println("************图书管理系统***********");
                        System.out.println("1.管理员密码修改");
                        System.out.println("2.操作员密码修改");
                        System.out.println("3.退出");
                        System.out.println("请选择：");
                        String number2 = sc.next();
                        switch (number2) {
                            case "1":
                                System.out.println("请输入管理员编号：");
                                String id3 = TSUtility.readKeyBoard(11, false);
                                System.out.println("请输入原密码：");
                                String PassWord = TSUtility.readKeyBoard(11, false);
                                System.out.println("请输入新密码：");
                                String newPassWord = TSUtility.readKeyBoard(11, false);
                                if (managerDao.selectBYManager(id3) == null) {
                                    System.out.println("没有该管理员账号！！！");
                                    break;
                                }
                                LoginService.updateManagerPassWord(id3, PassWord, newPassWord);
                                System.out.println("修改成功！");
                                break;
                            case "2":
                                System.out.println("请输入操作员账号：");
                                String name = TSUtility.readKeyBoard(11, false);
                                System.out.println("请输入原密码：");
                                String PassWord1 = TSUtility.readKeyBoard(11, false);
                                System.out.println("请输入新密码：");
                                String newPassWord1 = TSUtility.readKeyBoard(11, false);
                                if (operatorDao.selectBYOperator(name) == null) {
                                    System.out.println("没有该操作员账号！！！");
                                    break;
                                }
                                LoginService.updateOperatorPassWord(name, PassWord1, newPassWord1);
                                break;
                            case "3":
                                option2 = false;
                                break;
                            default:
                                System.out.println("没有" + number2 + "这个选项！");
                                break;
                        }
                    }
                    break;
                case "5":
                    option = false;
                    break;
                default:
                    System.out.println("没有" + number + "这个选项！");
                    break;
            }
        }

    }
}